#!/bin/sh

# Part of Zombie Navigator
# Copyright © 2016  Zombie Navigator Developers

cd "`dirname "$0"`"/..

. ./version_info

addon_version="`echo "$addon_version" | tr -d '~-'`"

if [ "$addon_multiprocess" ] ; then
	multiprocess=',"multiprocess": true'
else
	multiprocess=''
fi

git="`git show -s --pretty=format:%H 2>/dev/null | head -c 8`"
touch ./src/build.meta
[ "$git" ] && {
	version_git="+git.$git"
	printf '//Build:git-%s' "$git" > ./src/build.meta
	git_changes="`git status -s`"
	[ "$git_changes" ] && version_git="${version_git}+uncommitted"
}

[ "$addon_release_phase" = stable ] && version_git=''

# TODO: Refactor things
cat <<EOF | sed 's/^\s*//' | tr -d '\n' | sed 's/"\s*:\s*/":/g' > ./src/package.json
{
  "title": "${addon_name}"
  ,"name": "${addon_id}"
  ,"version": "${addon_version}${version_git}"
  ,"description": "${addon_description}"
  ,"main": "index.js"
  ,"author": "${addon_author}"
  ,"engines": {
    "firefox": ">=38.0a1"
  }
  ,"license": "AGPL-3.0+"
  ,"permissions": {
    "private-browsing": true
    ${multiprocess}
  }
  ,"preferences": [
    {
      "name": "ignoreEnvironmentScript"
      ,"type": "bool"
      ,"value": false
      ,"hidden": true
      ,"title": "Deprecated"
    }
    ,{
      "name": "ignoreEnvironment"
      ,"type": "bool"
      ,"value": false
      ,"title": "Do not interpret environment variables"
      ,"description": "Scripts specified in a variable will be ignored. Enable if you don't need command-line access"
    }
    ,{
      "name": "hideSystemDetails"
      ,"type": "bool"
      ,"value": false
      ,"title": "Hide system details from Zombie scripts"
      ,"description": "Don't disclose real OS, browser version, etc. to Zombie scripts. Note: some of the values are available to content scripts. This option helps when you spoof those values to Web contents."
    }
    ,{
      "name": "allowApps"
      ,"type": "bool"
      ,"value": false
      ,"hidden": true
      ,"title": "Allow in-browser Zombie Navigator Apps"
      ,"description": "Enable if you want to use a Zombie Navigator App installed as a browser extension."
    }
    ,{
      "name": "policy.closeFinished"
      ,"type": "bool"
      ,"value": true
      ,"title": "Global policy: Close a Zombie window when finished"
    }
    ,{
      "name": "policy.downloads"
      ,"type": "bool"
      ,"value": true
      ,"title": "Global policy: Script-initiated file downloads"
    }
    ,{
      "name": "policy.screenshots"
      ,"type": "bool"
      ,"value": true
      ,"title": "Global policy: Scripted screenshots of window contents"
    }
    ,{
      "name": "policy.noBrowserURIs"
      ,"type": "bool"
      ,"value": false
      ,"title": "Global policy: Disallow the browser's internal pages"
      ,"description": "This keeps Zombie scripts from even just opening the affected pages (such as preferences)"
    }
    ,{
      "name": "policy.noBrowserScripts"
      ,"type": "bool"
      ,"value": true
      ,"title": "Global policy: No scripting on the browser's internal pages"
      ,"description": "Turn off to test the browser itself (Do it only if you know what you're doing!)"
    }
    ,{
      "name": "policy.noLocalURIs"
      ,"type": "bool"
      ,"value": false
      ,"title": "Global policy: Disable access to local files"
      ,"description": "Restrict access to file:// URIs"
    }
    ,{
      "name": "policy.privateBrowsingContext"
      ,"type": "menulist"
      ,"value": 0
      ,"title": "Global policy: Allowed scripting context"
      ,"description": "Types of windows Zombie scripts can open (Note that each script can only access its own Zombie windows)"
      ,"options": [
      	{"value": 0, "label": "Normal and Private-Browsing windows"}
      	,{"value": 1, "label": "Only Normal windows"}
      	,{"value": 2, "label": "Only Private-Browsing windows"}
      ]
    }
    ,{
      "name": "policy.scriptTimeout"
      ,"type": "menulist"
      ,"value": -1
      ,"title": "Global policy: Script session timeout"
      ,"description": "Maximum length of a Zombie session. You can always terminate a script."
      ,"options": [
      	{"value": -1, "label": "Unlimited (default)"}
      	,{"value": 60, "label": "1 minute"}
      	,{"value": 180, "label": "3 minutes"}
      	,{"value": 300, "label": "5 minutes"}
      	,{"value": 600, "label": "10 minutes"}
      	,{"value": 1800, "label": "30 minutes"}
      	,{"value": 3600, "label": "1 hour"}
      	,{"value": 7200, "label": "2 hours"}
      	,{"value": 10800, "label": "3 hours"}
      	,{"value": 21600, "label": "6 hours"}
      	,{"value": 43200, "label": "12 hours"}
      	,{"value": 86400, "label": "24 hours"}
      ]
    }
    ,{
      "name": "consoleLevel"
      ,"type": "menulist"
      ,"value": 1
      ,"title": "Console output"
      ,"options": [
      	{"value": 3, "label": "All messages"}
      	,{"value": 2, "label": "Detailed"}
      	,{"value": 1, "label": "Important messages only (default)"}
      	,{"value": 0, "label": "Suppressed"}
      ]
    }
    ,{
      "name": "disableAddonUI"
      ,"type": "bool"
      ,"value": false
      ,"title": "Disable active addon UIs"
      ,"description": "Remove some active control elements from the addon's interfaces: no effect on Zombie scripts, recommended for noninteractive uses"
    }
    ,{
      "name": "showHelp"
      ,"type": "bool"
      ,"value": true
      ,"title": "Show help on startup"
    }
    ,{
      "name": "showHelpOnce"
      ,"type": "bool"
      ,"value": true
      ,"title": "Disable 'help on startup' once shown"
    }
    ,{
      "type": "control"
      ,"name": "button-help"
      ,"label": "Help"
      ,"title": "Show help now"
    }
    ,{
      "type": "control"
      ,"name": "button-license"
      ,"label": "Show"
      ,"title": "License information"
    }
    ,{
      "type": "control"
      ,"name": "button-dashboard"
      ,"hidden": true
      ,"label": "Dashboard"
      ,"title": "Zombie Navigator Status"
      ,"description": "See and control runnning scripts"
    }
    ,{
      "type": "control"
      ,"name": "button-stop"
      ,"label": "Stop"
      ,"title": "Terminate all running Zombie scripts now"
    }
    ,{
      "type": "file"
      ,"name": "temp-scriptPath"
      ,"title": "Run a Zombie script now"
    }
    ,{
      "type": "file"
      ,"name": "temp-scriptConfigPath"
      ,"hidden": true
      ,"title": "Execute a Zombie Script Configuration now"
      ,"description": "This is a special JSON file with instructions about how to run Zombie scripts. Zombie Navigator will run the script(s) as specified in it."
    }
  ]
}
EOF

# vim: ts=4 noet ai

